package com.qianyu.project.service.impl;

import com.qianyu.project.entity.MaterialOutstorageRecord;
import com.qianyu.project.entity.MaterialOutstorageRecordDetail;
import com.qianyu.project.mapper.MaterialOutstorageRecordMapper;
import com.qianyu.project.service.IMaterialOutstorageRecordDetailService;
import com.qianyu.project.service.IMaterialOutstorageRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 材料出库记录 服务实现类
 * </p>
 *
 * @author gs
 * @since 2021-01-30
 */
@Service
public class MaterialOutstorageRecordServiceImpl extends ServiceImpl<MaterialOutstorageRecordMapper, MaterialOutstorageRecord> implements IMaterialOutstorageRecordService {

    @Autowired
    private MaterialOutstorageRecordMapper mapper;

    @Autowired
    private IMaterialOutstorageRecordDetailService detailservice;
    /**
     *添加出库
     * description:  <br/>
     * author: lyz   <br/>
     * date: 2021/2/21 <br/>
     * params:  <br/>
     * return:
     */
    @Override
    public void addOutstorage(MaterialOutstorageRecord record, List<MaterialOutstorageRecordDetail> detailList) {
        BigDecimal decimal=new BigDecimal(0);
        detailList.forEach(d->{
            decimal.add(d.getSumAmount());
        });
        record.setInstorageAmount(decimal);
        mapper.insert(record);
        detailList.forEach(d->{
            d.setInstorageId(record.getId());
        });
        detailservice.saveBatch(detailList);
    }
}
